package com.flw.eslab.action.admin;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.apache.struts2.json.annotations.JSON;
import org.springframework.stereotype.Controller;

import com.flw.eslab.dto.PageInfo_Dto;
import com.flw.eslab.dto.Report_Dto;
import com.flw.eslab.service.ReportManager;
import com.flw.eslab.service.UserManager;

@Controller
@Results({
	@Result(name = "tolist", location = "info?jump_url=list", type = "redirect"),
	@Result(name = "toAdd", location = "info?jump_url=add", type = "redirect")})
public class ReportAction extends CommonAction {

	private Report_Dto report_Dto = new Report_Dto();
	@Resource
	private ReportManager reportManager;
	private PageInfo_Dto pageInfo_Dto;
	
	public ReportManager getReportManager() {
		return reportManager;
	}

	public PageInfo_Dto getPageInfo_Dto() {
		return pageInfo_Dto;
	}

	public void setPageInfo_Dto(PageInfo_Dto pageInfo_Dto) {
		this.pageInfo_Dto = pageInfo_Dto;
	}

	public String add() {
		if(reportManager.add(report_Dto.toReport())){
			session.put("msg", "报告添加成功");
			return "tolist";
		}
		else{
			session.put("msg", "报告添加不成功");
			return "toAdd";
		}
	}
	
	public String delete(){
		if(reportManager.delete(report_Dto.toReport())){
			session.put("msg", "报告删除成功");
			return "tolist";
		}else{
			session.put("msg", "报告删除不成功");
			return "tolist";
		}
	}

	public String load() {
		
		setPageInfo_Dto(reportManager.load(pageInfo_Dto));
		session.put("pageInfo_Dto", pageInfo_Dto);
		return "success";
	}

	public String update() {
		
		if(reportManager.modify(report_Dto.toReport())){
			session.put("msg", "报告删除成功");
			return "tolist";
		}else{
			session.put("msg", "报告删除不成功");
			return "tolist";
		}
	}

	/*--------------------------------*/

	public Report_Dto getReport_Dto() {
		return report_Dto;
	}

	public void setReport_Dto(Report_Dto report_Dto) {
		this.report_Dto = report_Dto;
	}

	public void setReportManager(ReportManager reportManager) {
		this.reportManager = reportManager;
	}
}
